<template>
  <div class="print-container">
    <div class="print-title">{{ title }}</div>
    <!-- 入库单 字段 -->
    <div v-if="type === 'editor'" class="print-info">
      <div class="print-info-cell">
        <label>出品人：</label>{{ info.user_name }}
      </div>
      <div class="print-info-cell">
        <label>日期：</label>{{ parseTime(new Date(), '{y}-{m}-{d}') }}
      </div>
    </div>
    <!-- 付款提货单 字段 -->
    <div v-if="type === 'settle_buy'" class="print-info">
      <div class="print-info-cell">
        <label>号牌：</label>{{ info.user_num }}
      </div>
      <div class="print-info-cell">
        <label>专场名称：</label>{{ info.lotName }}-{{ info.lotId }}
      </div>
      <div class="print-info-cell">
        <label>购买人：</label>{{ info.user_name }}
      </div>
      <div class="print-info-cell">
        <label>日期：</label>{{ parseTime(new Date(), '{y}-{m}-{d}') }}
      </div>
      <div class="print-info-cell">
        <label>地址：</label>{{ info.address }}
      </div>
    </div>
    <!-- 卖家结算单 字段 -->
    <div v-if="type === 'settle_send'" class="print-info">
      <div class="print-info-cell">
        <label>号牌：</label>{{ info.user_num }}
      </div>
      <div class="print-info-cell">
        <label>专场名称：</label>{{ info.lotName }}-{{ info.lotId }}
      </div>
      <div class="print-info-cell">
        <label>订单编号：</label>{{ info.order_number }}
      </div>
      <div class="print-info-cell">
        <label>日期：</label>{{ parseTime(new Date(), '{y}-{m}-{d}') }}
      </div>
      <div class="print-info-cell">
        <label>出品人：</label>{{ info.user_name }}
      </div>
      <div class="print-info-cell">
        <label>出品人编号：</label>{{ info.user_num }}
      </div>
      <div class="print-info-cell">
        <label>转账银行：</label>{{ info.bankname }}
      </div>
      <div class="print-info-cell">
        <label>银行卡号：</label>{{ info.bankcard }}
      </div>
    </div>
    <el-table
      ref="printTable"
      border
      :data="list"
      show-summary
    >
      <el-table-column key="number" prop="number" label="图录号" align="center" width="80" />
      <el-table-column key="name" prop="name" label="拍品名" align="left" header-align="center" />
      <el-table-column v-if="type === 'settle_send'" key="catafee" prop="catafee" label="图录费" align="right" header-align="center" width="85" :formatter="formatPrice" />
      <template v-if="type === 'settle_buy' || type === 'settle_send'">
        <el-table-column key="final_price" prop="final_price" label="成交价" align="right" header-align="center" width="110" :formatter="formatPrice" />
        <el-table-column key="fee" prop="fee" label="手续费" align="right" header-align="center" width="95" :formatter="formatPrice" />
        <el-table-column key="tax" prop="tax" label="税费" align="right" header-align="center" width="95" :formatter="formatPrice" />
        <el-table-column v-if="type === 'settle_buy'" key="postage" prop="postage" label="邮寄费" align="right" header-align="center" width="95" :formatter="formatPrice" />
        <el-table-column key="sum" prop="sum" label="合计" align="right" header-align="center" width="110" :formatter="formatPrice" />
      </template>
    </el-table>
    <div v-if="type === 'settle_buy'" class="print-info">
      <div class="print-info-cell">
        <label>其他费用：</label>{{ toThousands(info.other_fee) }}
      </div>
      <div class="print-info-cell">
        <label>汇率：</label>{{ info.lot_rate }}
      </div>
      <div class="print-info-cell">
        <label>应付金额：</label>{{ toThousands(info.price) }}
      </div>
      <div class="print-info-cell">
        <label>应付人民币：</label>{{ toThousands(info.price_rmb) }}
      </div>
    </div>
  </div>
</template>
<script>
import { parseTime, toThousands } from '@/utils'
export default {
  name: 'PrintTable',
  props: {
    // editor settle_buy settle_send
    type: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: ''
    },
    info: {
      type: Object,
      default: () => ({})
    },
    list: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    parseTime,
    toThousands,
    formatPrice (row, column, cellValue, index) {
      return this.toThousands(cellValue)
    }
  }
}
</script>
<style lang="scss" scoped>
.print-title {
  line-height: 24px;
  font-size: 18px;
  color: #303133;
  text-align: center;
  margin: 0 0 24px;
  font-weight: bold;
}
.print-info {
  display: flex;
  width: 100%;
  margin-bottom: 20px;
  flex-wrap: wrap;
  &-cell {
    width: 50%;
    line-height: 35px;
  }
}
.el-table {
  width: 100%;
  margin-bottom: 15px;
}
</style>
